second submit button on top, input instead of button for more consistent styling...
[lhc/web/wiklou.git] / includes / PageHistory.php
1 <?php
2
3 /* Page history
4 Split off from Article.php and Skin.php, 2003-12-22
5 */
6
7 class PageHistory {
8 var $mArticle, $mTitle, $mSkin;
9 var $lastline, $lastdate;
10 var $linesonpage;
11 function PageHistory( $article ) {
12 $this->mArticle =& $article;
13 $this->mTitle =& $article->mTitle;
14 }
15
16 # This shares a lot of issues (and code) with Recent Changes
17
18 function history()
19 {
20 global $wgUser, $wgOut, $wgLang;
21
22 # If page hasn't changed, client can cache this
23
24 if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){
25 # Client cache fresh and headers sent, nothing more to do.
26 return;
27 }
28 $fname = "PageHistory::history";
29 wfProfileIn( $fname );
30
31 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
32 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
33 $wgOut->setArticleFlag( false );
34 $wgOut->setArticleRelated( true );
35 $wgOut->setRobotpolicy( "noindex,nofollow" );
36
37 if( $this->mTitle->getArticleID() == 0 ) {
38 $wgOut->addHTML( wfMsg( "nohistory" ) );
39 wfProfileOut( $fname );
40 return;
41 }
42
43 list( $limit, $offset ) = wfCheckLimits();
44
45 /* We have to draw the latest revision from 'cur' */
46 $rawlimit = $limit;
47 $rawoffset = $offset - 1;
48 if( 0 == $offset ) {
49 $rawlimit--;
50 $rawoffset = 0;
51 }
52 /* Check one extra row to see whether we need to show 'next' and diff links */
53 $limitplus = $rawlimit + 1;
54
55 $namespace = $this->mTitle->getNamespace();
56 $title = $this->mTitle->getText();
57 $sql = "SELECT old_id,old_user," .
58 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
59 "FROM old USE INDEX (name_title_timestamp) " .
60 "WHERE old_namespace={$namespace} AND " .
61 "old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
62 "ORDER BY inverse_timestamp LIMIT $rawoffset, $limitplus";
63 $res = wfQuery( $sql, DB_READ, $fname );
64
65 $revs = wfNumRows( $res );
66
67 if( $revs < $limitplus ) // the sql above tries to fetch one extra
68 $this->linesonpage = $revs;
69 else
70 $this->linesonpage = $revs - 1;
71
72 $atend = ($revs < $limitplus);
73
74 $this->mSkin = $wgUser->getSkin();
75 $numbar = wfViewPrevNext(
76 $offset, $limit,
77 $this->mTitle->getPrefixedText(),
78 "action=history", $atend );
79 $s = $numbar;
80 $this->submitbuttonhtml = ( $this->linesonpage > 1) ? '<li class="histsubmitli">
81 <input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
82 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions')."\" /></li>" :
83 '';
84 $s .= $this->beginHistoryList();
85 $counter = 1;
86 if( $offset == 0 ){
87 $this->linesonpage++;
88 $s .= $this->historyLine(
89 $this->mArticle->getTimestamp(),
90 $this->mArticle->getUser(),
91 $this->mArticle->getUserText(), $namespace,
92 $title, 0, $this->mArticle->getComment(),
93 ( $this->mArticle->getMinorEdit() > 0 ),
94 $counter++
95 );
96 }
97 while ( $line = wfFetchObject( $res ) ) {
98 $s .= $this->historyLine(
99 $line->old_timestamp, $line->old_user,
100 $line->old_user_text, $namespace,
101 $title, $line->old_id,
102 $line->old_comment, ( $line->old_minor_edit > 0 ),
103 $counter++
104 );
105 }
106 $s .= $this->endHistoryList( !$atend );
107 $s .= $numbar;
108 $wgOut->addHTML( $s );
109 wfProfileOut( $fname );
110 }
111
112 function beginHistoryList()
113 {
114 global $wgTitle;
115 $this->lastdate = $this->lastline = "";
116 $s = "\n<p>" . wfMsg( "histlegend" ).'</p>';
117 $s .="\n<form id=\"pagehistory\" name=\"pagehistory\" action=\"" . $wgTitle->getFullURL("-") . "\" method=\"get\">";
118 $s .= "<input type=\"hidden\" name=\"title\" value=\"".htmlspecialchars($wgTitle->getPrefixedDbKey())."\"/>\n";
119 $s .= "" . "\n<ul>";
120 $s .= !empty($this->submitbuttonhtml) ? $this->submitbuttonhtml."\n":'';
121 return $s;
122 }
123
124 function endHistoryList( $skip = false )
125 {
126 $last = wfMsg( "last" );
127
128 $s = $skip ? "" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
129 $s .= !empty($this->submitbuttonhtml) ? $this->submitbuttonhtml."\n":'';
130 $s .= "</ul></form>\n";
131 return $s;
132 }
133
134 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' )
135 {
136 global $wgLang;
137
138 $artname = Title::makeName( $ns, $ttl );
139 $last = wfMsg( "last" );
140 $cur = wfMsg( "cur" );
141 $cr = wfMsg( "currentrev" );
142
143 if ( $oid && $this->lastline ) {
144 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
145 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline );
146 } else {
147 $ret = "";
148 }
149 $dt = $wgLang->timeanddate( $ts, true );
150
151 if ( $oid ) {
152 $q = "oldid={$oid}";
153 } else {
154 $q = "";
155 }
156 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
157
158 if ( 0 == $u ) {
159 $ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( "Contributions" ),
160 $ut, "target=" . $ut );
161 } else {
162 $ul = $this->mSkin->makeLink( $wgLang->getNsText(
163 Namespace::getUser() ) . ":{$ut}", $ut );
164 }
165
166 $s = "<li>";
167 if ( $oid ) {
168 $curlink = $this->mSkin->makeKnownLink( $artname, $cur,
169 "diff=0&oldid={$oid}" );
170 } else {
171 $curlink = $cur;
172 }
173 $arbitrary = "";
174 if( $this->linesonpage > 1) {
175 # XXX: move title texts to javascript
176 $checkmark = "";
177 if ( !$oid ) {
178 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
179 $checkmark = ' checked="checked"';
180 } else {
181 if( $counter == 2 ) $checkmark = ' checked="checked"';
182 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
183 $checkmark = '';
184 }
185 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
186 }
187 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
188 $s .= $isminor ? ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
189
190
191 if ( "" != $c && "*" != $c ) {
192
193 $c = $this->mSkin->formatcomment($c);
194 $s .= " <em>(" . $c . ")</em>";
195 }
196 $s .= "</li>\n";
197
198 $this->lastline = $s;
199 return $ret;
200 }
201
202 }
203
204 ?>